using Avalonia;
using Avalonia.Controls;
using System;

namespace AvaloniaDrawingPad.Models.Commands
{
    /// <summary>
    /// 移动图形命令
    /// </summary>
    public class MoveShapeCommand : ICommand
    {
        private readonly Control _shape;
        private readonly double _oldLeft;
        private readonly double _oldTop;
        private readonly double _newLeft;
        private readonly double _newTop;
        private readonly LayerManager _layerManager;
        
        public string Description => "移动图形";
        
        public MoveShapeCommand(
            Control shape, 
            double oldLeft, 
            double oldTop, 
            double newLeft, 
            double newTop,
            LayerManager layerManager)
        {
            _shape = shape;
            _oldLeft = oldLeft;
            _oldTop = oldTop;
            _newLeft = newLeft;
            _newTop = newTop;
            _layerManager = layerManager;
        }
        
        public void Execute()
        {
            // 设置图形位置
            Canvas.SetLeft(_shape, _newLeft);
            Canvas.SetTop(_shape, _newTop);
            
            // 标记项目已修改
            _layerManager.MarkAsChanged();
        }
        
        public void Undo()
        {
            // 恢复图形位置
            Canvas.SetLeft(_shape, _oldLeft);
            Canvas.SetTop(_shape, _oldTop);
            
            // 标记项目已修改
            _layerManager.MarkAsChanged();
        }
    }
} 